import React,{Component} from 'react';
import {connect} from 'react-redux'
class Advertise extends Component{
    constructor(props){
        super(props);
        this.state={
            seconds:4
        }

    }
    render(){
        return(
            <div className='advertise'>
               <a className='click-to-home' onClick={this.toHome.bind(this)}>跳过&nbsp;{this.state.seconds}</a>
            </div>

        )
    }

    toHome(){
        this.props.history.replace('/do')
    }
    componentWillMount(){
        this.props.sendStatus();
    }
    componentDidMount(){
        setInterval(()=>{
            let second=this.state.seconds;
            let seconds=second-1;
            if(second<=0){
                this.setState({
                    seconds:4
                });
                this.props.history.replace('/do');
                return
            }
            this.setState({
                seconds:seconds
            })

        },1000);

    }
}



const mapDispatchToProps = dispatch => ({
    sendStatus: message => {
        dispatch({type: 'HIDE_HEAD'});
        dispatch({type: 'HIDE_FOOT'});
    },
});
export default connect(
    null,
    mapDispatchToProps
)(Advertise)